package com.atguigu.study.test;

import lombok.extern.slf4j.Slf4j;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

@Slf4j
public class SpringELDemo {
    public static void main(String[] args) {
//        1.log日志占位符替换
        log.info("log:{}","abcd");
        System.out.println();

//        2.spring.format占位符替换,%s 相当于一个 “空位”，
//        String.format 会把后续的参数按顺序填入这些 “空位” 中
        String result = String.format("%s,java","尚硅谷 (>^ω^<)喵");
        System.out.println(result);
        System.out.println();

//        3.springELExpress表达式，#号后面内容可以被替换
        String var = "#userid";
        SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
        Expression expression = spelExpressionParser.parseExpression(var);

        EvaluationContext context = new StandardEvaluationContext();
        context.setVariable("userid","1253");
        String s = expression.getValue(context).toString();
        System.out.println(s);

    }
}
